<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<body>
<script>
function Person(){
    this.name = "李四"
}
Person.prototype.age = 20;
//hasOwnProperty()
var p1 = new Person();
console.log("age" in p1)  // in会沿着原型链找
console.log("name" in p1)  // in会沿着原型链找

/*console.log(p1.hasOwnProperty("name"));
console.log(p1.hasOwnProperty("sex"));*/

function position(obj, proName){
    if(obj.hasOwnProperty(proName)){
        return "在对象上"
    }else if(proName in obj){
        return "在原型上"
    }else{
        return "不存在"
    }
}
console.log(position(p1, "age"));
console.log(position(p1, "age1"));
console.log(position(p1, "name"));

</script>
</body>
</html>